<?php
class DBException extends Exception {
	public function __construct($message, $code = 0) {
		parent::__construct($message, $code);
	}
	public function __toString() {
		$trace = $this->getTrace();
		return '<b>' . $this->message . '：</b> ' . $trace[0]['args'][0]->userinfo . ' <b>' . $trace[0]['file'] . '</b> on line ' . $trace[0]['line'];
	}
	public function custom() {
		$trace = $this->getTrace();
		$e['message'] = $this->message;
		$e['file'] = $trace[0]['file'];
		$e['class'] = $trace[0]['class'];
		$e['function'] = $trace[0]['function'];
		$e['line'] = $trace[0]['line'];
		$time = adodb_date("Y-m-d H:i:m");
		$e['trace'] = $trace[0]['args'][0]->userinfo;
		return $e;
	}
	public function getJSMessage() {
		if (isDebug()) {
			$trace = $this->getTrace();
			$detailMsg = str_replace(array("\r\n", "\t"), array('', '  '), $trace[0]['args'][0]->userinfo);
			$msg = "<div id='_debugmsg'>";
			$msg.= "<h2>DBException</h2>";
			$msg.= "<h6><b>错误位置：</b>FILE：<span>{$trace[0]['file']}</span> LINE：<span>{$trace[0]['line']}</span></h6>";
			$msg.= "<label>[错误信息]</label>";
			$msg.= "<p>{$this->message}</p>";
			$msg.= "<label>[TRACE]</label>";
			$msg.= "<div>    $detailMsg</div>";
			$msg.= "</div>";
		} else {
			$msg = $this->getNonDebugMsg();
		}
		return $msg;
	}
	//非调试模式下的提示内容
	public function getNonDebugMsg() {
		return '服务器内部错误，请与管理员联系，谢谢';
	}
}